clear

/*
use "C:\Local\数据\ex2005 data.dta"

egen ownership = group(firmtype)

egen country = group(partner)

gen hs6 = substr(hs8, 1, 6)

g xx = trader

  bys hs6 country: egen totv = sum(value)
  bys hs6 country: egen totv_t = sum(value) if xx==1
  
collapse (mean) totv*, by(partner country hs6) fast
		
  foreach v of varlist totv* {
	replace `v' = 0 if `v' == .
			}
g s = totv_t/totv

label variable s "intermediary export share by country-hs6"

merge m:m partner using "C:\Local\数据\Table 3\disance+population+GDP+document.dta" 

drop if _merge == 2

drop _merge

merge m:m partner hs6 using "C:\Local\数据\Table 3\hs6-mfn.dta"

drop if _merge == 2

drop _merge

drop partner totv totv_t GDP2005 distance population

save "C:\Local\数据\Table 3\table 3 data.dta", replace

*/

//Regression code for table 3

areg s lnDistance lnGDP, a(hs6) cluster(country)

areg s lnDistance lnGDP lnpopulation, a(hs6) cluster(country)

areg s lnDistance lnGDP lnpopulation tradeproc, a(hs6) cluster(country)

areg s lnDistance lnGDP lnpopulation tradeproc mfn, a(hs6) cluster(country)
